let currentCostId = window.localStorage.getItem("costId");

$(() => {

    $.post("/service/costCheck", resp => {

        let costInfo = $('#costInfo');
        if (resp.message === 'OK') {

            for (let i of resp.data) {

                let option = $('<option></option>').html(i.costName);
                option.attr("value", i.costId);

                if (currentCostId == i.costId) {
                    option.attr("selected", "selected");
                }

                costInfo.append(option);

            }

        }

    });


    $('#findAccount').click(function () {

        let idcardNo = $('#idcardNo').val();
        let params = {
            idcardNo: idcardNo
        };

        $.post("/service/findAccount", params, resp => {
            $('#accountId').val(resp.accountId);
        });

    });



    $('#submit').click(function () {

        let newCost = $('option:selected').val();
        let serviceId= $('#serviceId').val();
        if (currentCostId !== newCost) {

            console.log(newCost);
            console.log(serviceId);

            let params = {
                costId: newCost,
                serviceId: serviceId
            };

            $.post("/service/modifyBusiness", params);
            window.location.href = '/service/service_list.html';
            alert('已更改资费! 将于月底由程序自动完成业务所关联的资费!(假)');

        } else {
            alert('选了吗你就瞎点?!');
        }

    });





});